package com.wfc.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ConfigManage {
   static  Properties properties = null;
   static  ConfigManage configManage = null;

    //构造方法内以流的形式读取配置文件
   public ConfigManage(String path){
       try {
           properties = new Properties();
           File file = new File(path);
           InputStream fis = new FileInputStream(file);
           properties.load(fis);
       }catch (IOException e){
           e.printStackTrace();
       }
   }

   //调用构造方法创造ConfigManage实例对象
    public static ConfigManage getConfig(String path){
       try{
           if(configManage == null){
               configManage = new ConfigManage(path);
           }
       }catch (Exception e) {
           e.printStackTrace();
       }
       return configManage;
    }

    //利用Properties对象获取配置文件属性
    public static String getValue(String key){
       if (properties != null){
           return properties.getProperty(key);
       }else {
           return "没有该属性";
       }
    }

}
